Imports CPassword
Public Class frmTestPassword
  Inherits System.Windows.Forms.Form
  Dim MyCheck As New CPassword()

           Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As _
                 System.EventArgs) Handles btnAdd.Click
    Dim length, Level, Passed As Integer

    If txtSecurity.Text = "" Then
      MessageBox.Show("Prosz wprowadzi poziom bezpieczestwa.")
      Exit Sub
    End If
    Level = CInt(txtSecurity.Text)
    Passed = MyCheck.AddNewUser(txtName.Text, txtPassword.Text, Level)
    If Passed = False Then  ' Sprawdza, czy uytkownik moe by dodany.
      Beep()         ' Pewnie nie...
      length = Len(txtPassword.Text)
      If length < 4 Or length > 30 Then   ' Czy dugo hasa jest OK?
        MessageBox.Show("Bd. Dugo hasa musi si zawiera" & _ 
                    "midzy 4 a 30 znakami.")
        txtPassword.Text = ""
        txtConfirm.Text = ""
        txtPassword.Focus()
      ElseIf Level < 1 Or Level > 10 Then  ' Co z poziomem 
                                           ' bepieczestwa?
        MessageBox.Show("Bd. Poziom bezpieczestwa musi by" & _
                    "pomidzy 1 a 10")
        txtSecurity.Text = ""
        txtSecurity.Focus()
      Else                 ' Ju jest na licie.
        MessageBox.Show("Bd. Nazwa uytkownika ju jest na licie")
      End If
      Exit Sub
    End If
    ' Jeli doszlimy tutaj, wszystko jest OK.
    MessageBox.Show("Dodanie uytkownika do listy powiodo si")
  End Sub

  Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As _
                  System.EventArgs) Handles btncheck.Click
    Dim Password As String, SecurityLevel As Integer

    Password = MyCheck.GetPassword(txtName.Text, txtPassword.Text)
    SecurityLevel = MyCheck.GetSecurityLevel(txtName.Text)

  End Sub

  Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As _
                 System.EventArgs) Handles btnExit.Click

    MyCheck = Nothing      ' To zwalnia obiekt 
    Me.Dispose()
  End Sub


  Private Sub txtConfirm_Leave(ByVal sender As Object, ByVal e As _
                   System.EventArgs) Handles txtConfirm.Leave
    If txtConfirm.Text <> txtPassword.Text Then
      MessageBox.Show("Dwa hasa nie zgadzaj si.")
      txtPassword.Text = ""
      txtConfirm.Text = ""
      txtPassword.Focus()
    End If
  End Sub
End Class
